<html>
<head>
<meta charset="UTF-8">
<title>资源定义新增</title>
<link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">
	<form id="ff" method="post">
		<div class="esaas-info-title">资源定义信息</div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">资源ID：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="resourceid" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">资源名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="cnname" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">资源URL：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="url" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">上级资源ID：</td>
				<td width="35%"><input class="easyui-textbox" type="text" readonly
									   id="parentid" name="parentid" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">序号：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="orderid" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>

			</tr>
		</table>
	</form>
	<div class="esaas-info-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton " iconCls="icon-ok" onclick="submitForm()" style="width:90px">&nbsp;保&nbsp;存&nbsp;</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeForm()" style="width:90px">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>

		var roleno;

		$(function() {
            addTitle("新增");
            //给上级资源ID赋值
            $('#parentid').textbox('setValue', $.getUrlParam('resourceid'));
            //获取角色列表
			getRolesNumber();
		});

        function getRolesNumber(){
            $.ajax({
                type: "POST",
                url: '../../api/s/roleusers',
                data: {actorno:$.getUrlParam('actorno')},
                success: function(data) {
					roleno=data.rows[0].roleno;
                }
            });
        }

		function submitForm() {
			if (!$('#ff').form('validate')||roleno==null){
				$.messager.alert('提示','表单填写不规范或当前用户没有设置操作角色!','info');
				return;}
			var jsonData = $("#ff").serializeJson();
			jsonData.systempk=$.getUrlParam('systempk');
			console.log("jsonData.systempk="+jsonData.systempk);
			$.restfulPostJson('../../api/s/resource', jsonData, function(data) {
                //资源定义
                var actionJsondate=JSON.parse('{'+'"descr":"' + '菜单访问' + '"'
                    + ','+'"resourceid":"' + jsonData.resourceid + '"'
                    + ','+'"actid":"' + 'visit' + '"'+'}');
                $.restfulPostJson('../../api/s/resourceaction', actionJsondate, function(data) {
                });
                //资源操作
                var roleJsondate=JSON.parse('{'+'"roleno":"' + roleno + '"'
                    + ','+'"resourceid":"' + jsonData.resourceid + '"'
                    + ','+'"actIdStr":"' + 'visit' + '"'+'}');
                $.restfulPostJson('../../api/s/role/right/save', roleJsondate, function(data) {
                });
				window.parent.reloadTree();
			});
		};
		
		function closeForm() {
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>